package com.metier;

import java.io.Serializable;
import java.util.ArrayList;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.dao.UtilisateurBasiqueDAO;
import com.dao.UtilisateurDAO;


/**
 * This is an object that contains data related to the news table.
 * Do not modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 *
 * @hibernate.class
 *  table="news"
 */

public abstract class BaseNews  implements Serializable {

	public static String REF = "News";
	public static String PROP_FK_ETU = "FkEtu";
	public static String PROP_FK_EXP = "FkExp";
	public static String PROP_ID_TYPE = "IdType";
	public static String PROP_ID = "Id";
	public static String PROP_FK_USER = "FkUser";
	public static String PROP_FK_USER2 = "FkUser2";

	// constructors
	public BaseNews () {
		initialize();
	}

	/**
	 * Constructor for primary key
	 */
	public BaseNews (java.lang.Integer id) {
		this.setId(id);
		initialize();
	}

	/**
	 * Constructor for required fields
	 */
	public BaseNews (
		java.lang.Integer id,
		com.metier.TypeNews idType) {

		this.setId(id);
		this.setIdType(idType);
		initialize();
	}

	protected void initialize () {}



	private int hashCode = Integer.MIN_VALUE;

	// primary key
	private java.lang.Integer id;

	// many to one
	private com.metier.TypeNews idType;
	private com.metier.Etude fkEtu;
	private com.metier.Experience fkExp;
	private com.metier.Utilisateur fkUser;
	private com.metier.Utilisateur fkUser2;

	// collections
	private java.util.Set<com.metier.Utilisateur> utilisateurs;



	/**
	 * Return the unique identifier of this class
     * @hibernate.id
     *  generator-class="sequence"
     *  column="id_news"
     */
	public java.lang.Integer getId () {
		return id;
	}

	/**
	 * Set the unique identifier of this class
	 * @param id the new ID
	 */
	public void setId (java.lang.Integer id) {
		this.id = id;
		this.hashCode = Integer.MIN_VALUE;
	}




	/**
	 * Return the value associated with the column: id_type
	 */
	public com.metier.TypeNews getIdType () {
		return idType;
	}

	/**
	 * Set the value related to the column: id_type
	 * @param idType the id_type value
	 */
	public void setIdType (com.metier.TypeNews idType) {
		this.idType = idType;
	}



	/**
	 * Return the value associated with the column: fk_etu
	 */
	public com.metier.Etude getFkEtu () {
		return fkEtu;
	}

	/**
	 * Set the value related to the column: fk_etu
	 * @param fkEtu the fk_etu value
	 */
	public void setFkEtu (com.metier.Etude fkEtu) {
		this.fkEtu = fkEtu;
	}



	/**
	 * Return the value associated with the column: fk_exp
	 */
	public com.metier.Experience getFkExp () {
		return fkExp;
	}

	/**
	 * Set the value related to the column: fk_exp
	 * @param fkExp the fk_exp value
	 */
	public void setFkExp (com.metier.Experience fkExp) {
		this.fkExp = fkExp;
	}



	/**
	 * Return the value associated with the column: fk_user
	 */
	public com.metier.Utilisateur getFkUser () {
		//fkUser = UtilisateurDAO.seConnecter(id)
		return fkUser;
	}
	
	/**
	 * Return the value associated with the column: fk_user2
	 */
	public com.metier.Utilisateur getFkUser2 () {
		return fkUser2;
	}

	/**
	 * Set the value related to the column: fk_user
	 * @param fkUser the fk_user value
	 */
	public void setFkUser (com.metier.Utilisateur fkUser) {
		this.fkUser = fkUser;
	}
	
	/**
	 * Set the value related to the column: fk_user2
	 * @param fkUser2 the fk_user2 value
	 */
	public void setFkUser2 (com.metier.Utilisateur fkUser2) {
		this.fkUser2 = fkUser2;
	}



	/**
	 * Return the value associated with the column: Utilisateurs
	 */
	public java.util.Set<com.metier.Utilisateur> getUtilisateurs () {
		return utilisateurs;
	}

	/**
	 * Set the value related to the column: Utilisateurs
	 * @param utilisateurs the Utilisateurs value
	 */
	public void setUtilisateurs (java.util.Set<com.metier.Utilisateur> utilisateurs) {
		this.utilisateurs = utilisateurs;
	}

	public ArrayList<INews> getNews(){
		Session session = SessionManager.currentSession();
		Transaction tx = session.beginTransaction();
		UtilisateurBasique uc = (UtilisateurBasique) session.load(UtilisateurBasique.class, new Integer(22));
		ArrayList<INews> i = uc.getNews(10);
		SessionManager.closeSession();
		return i;
	}



	public boolean equals (Object obj) {
		if (null == obj) return false;
		if (!(obj instanceof com.metier.News)) return false;
		else {
			com.metier.News news = (com.metier.News) obj;
			if (null == this.getId() || null == news.getId()) return false;
			else return (this.getId().equals(news.getId()));
		}
	}

	public int hashCode () {
		if (Integer.MIN_VALUE == this.hashCode) {
			if (null == this.getId()) return super.hashCode();
			else {
				String hashStr = this.getClass().getName() + ":" + this.getId().hashCode();
				this.hashCode = hashStr.hashCode();
			}
		}
		return this.hashCode;
	}


	public String toString () {
		return super.toString();
	}


}